cmake_minimum_required(VERSION 3.6)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_BUILD_TYPE RELEASE)

# 设置编译标志位 增加了 -fPIC
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-unused-function")

project(OkRedis)

set(HEADER_H_LIST OkRedis.h OkRedisCore.h OkRedisReply.h)
set(CPP_LIST OkRedis.cpp OkRedisCore.cpp OkRedisReply.cpp)

option(ENABLE_DEMO "enable demo ?" ON)

include_directories(
        3rd/
)

set(HEADERS_HIREDIS
        3rd/hiredis/dict.h
        3rd/hiredis/sdsalloc.h
        3rd/hiredis/async.h
        3rd/hiredis/sds.h
        3rd/hiredis/hiredis.h
        3rd/hiredis/fmacros.h
        3rd/hiredis/net.h
        3rd/hiredis/read.h
        3rd/hiredis/adapters/libuv.h
        )

set(SRC_HIREDIS
        3rd/hiredis/dict.c
        3rd/hiredis/sds.c
        3rd/hiredis/net.h
        3rd/hiredis/read.c
        3rd/hiredis/async.c
        3rd/hiredis/net.c
        3rd/hiredis/hiredis.c
        )

if (ENABLE_DEMO)
    add_subdirectory(Demo)
endif ()

find_package(Boost 1.58.0 REQUIRED)
include_directories(${Boost_INCLUDES})
add_library(OkRedis SHARED ${HEADERS_HIREDIS} ${SRC_HIREDIS} ${HEADER_H_LIST} ${CPP_LIST})

target_link_libraries(OkRedis LINK_PUBLIC pthread)
target_link_libraries(OkRedis LINK_PUBLIC glog)
target_link_libraries(OkRedis LINK_PUBLIC uv)
target_link_libraries(OkRedis LINK_PUBLIC OrionV2)

install(TARGETS OkRedis LIBRARY DESTINATION /usr/local/lib
        PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE)

install(FILES ${HEADERS_HIREDIS} DESTINATION /usr/local/include/OkRedis/hiredis)
install(FILES ${HEADER_H_LIST} DESTINATION /usr/local/include/OkRedis)
install(FILES ${HEADER_HPP_LIST} DESTINATION /usr/local/include/OkRedis)
